<?php
/***************************************************************
*  Copyright notice
*
*  (c) 2011 Florian Müller <it-admin@ifp-potsdam.co>, IFP
*  
*  All rights reserved
*
*  This script is part of the TYPO3 project. The TYPO3 project is
*  free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 3 of the License, or
*  (at your option) any later version.
*
*  The GNU General Public License can be found at
*  http://www.gnu.org/copyleft/gpl.html.
*
*  This script is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

/**
 * Turnus
 */
class Tx_IfpCurriculum2_Domain_Model_Turnus extends Tx_Extbase_DomainObject_AbstractEntity {

	
	/**
	 * Modul Name
	 *
	 * @var string
	 * @validate NotEmpty
	 */
	protected $name;

	

	/**
	 * wieviele Turnusse gibt es
	 *
	 * @var integer
	 */
	protected $turnusTyp;

	/**
	 * Semester in dem der Turnus startet
	 *
	 * @var integer
	 */
	protected $turnusStartSemId;

	/**
	 * Turnus
	 *
	 * @var integer
	 */
	protected $turnus;



	/**
	 * @param string $name
	 * @return void
	 */
	public function setName($name) {
		$this->name = $name;
		echo 1;
	}

	/**
	 * @return string
	 */
	public function getName() {
		return $this->name;
	}

	

	/**
	 * @param integer $turnusTyp
	 * @return void
	 */
	public function setTurnusTyp($turnusTyp) {
		$this->turnusTyp = $turnusTyp;
	}

	/**
	 * @return integer
	 */
	public function getTurnusTyp() {
		return $this->turnusTyp;
	}

	/**
	 * @param integer $turnusStartSemId
	 * @return void
	 */
	public function setTurnusStartSemId($turnusStartSemId) {
		$this->turnusStartSemId = $turnusStartSemId;
	}

	/**
	 * @return integer
	 */
	public function getTurnusStartSemId() {
		return $this->turnusStartSemId;
	}
/**
	 * @param integer $turnusStartSemId
	 * @return void
	 */
	public function setTurnus($turnus) {
		$this->turnus = $turnus;
	}

	/**
	 * @return integer
	 */
	public function getTurnus() {
		return $this->turnus;
	}
	/**
	 * 
	 * Enter description here ...
	 * @return Tx_IfpCurriculum2_Domain_Model_Semester
	 */
	public function getNextSemester(){
		$semesterRepository = t3lib_div::makeInstance('Tx_IfpCurriculum2_Domain_Repository_SemesterRepository');
		
		$start=$this->getTurnusStartSemId();
		$nowSemester=$semesterRepository->getSemCurrent();
		$now=$nowSemester->getUid();
		
		$aktuellerTurnus=($now-$start)%$this->getTurnusTyp()+1;
		if($aktuellerTurnus==$this->turnus){
			return $nowSemester;
		}
		
		$div=$this->turnus-$aktuellerTurnus;
		if($div<0){
			return $semesterRepository->findByUid(($this->turnusTyp+$div)+$now);
		}else{
			return $semesterRepository->findByUid($div+$now);
		}
	}
	public function getText(){
		return $this->turnusTyp."wied. nächste Semester: ".$this->getNextSemester()->getBezeichnung();

	}
	

}
?>